package com.miracle.moa.gateway.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;

/**
 * @author : miracle
 * @version : 1.0.0
 * @date : 2021/3/22 22:07
 */
@Service
public class AuthService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    /**
     * 获取请求中的token
     * @param request
     * @return
     */
    public String getJtiFromHeaders(ServerHttpRequest request) {
        String token = request.getHeaders().getFirst("token");
        if (token != null) {
            return token;
        }
        return null;
    }

    /**
     * 判断redis中令牌是否过期
     *
     * @param jti
     * @return
     */
    public String getTokenFromRedis(String jti) {
        return stringRedisTemplate.boundValueOps(jti).get();
    }

}
